﻿#pragma once

#include <glad/glad.h>

#include "function/RenderSystem/AbstractBuffer.h"

namespace Engine
{
	class OpenGLVertexBuffer final : public VertexBuffer
	{
	public:
		OpenGLVertexBuffer(const float* vertices, uint32_t size);
		virtual ~OpenGLVertexBuffer() override;

		void Bind() const override;
		void UnBind() const override;

		inline virtual const BufferLayout& GetLayout() const override { return layout; }
		virtual void SetLayout(const BufferLayout& layout) override;

	private:
		GLuint rendererID;
		BufferLayout layout;
	};

	class OpenGLIndexBuffer final : public IndexBuffer
	{
	public:
		OpenGLIndexBuffer(const unsigned int* indices, uint32_t count);
		virtual ~OpenGLIndexBuffer() override;

		void Bind() const override;
		void UnBind() const override;
		uint32_t GetCount() const override;

	private:
		GLuint rendererID;
		uint32_t count;
	};

	class OpenGLVertexArray final : public VertexArray
	{
	public:
		OpenGLVertexArray();
		~OpenGLVertexArray() override;

		void Bind() const override;
		void UnBind() const override;

		void AddVertexBuffer(const Ref<VertexBuffer>& vertexBuffer) override;
		void SetIndexBuffer(const Ref<IndexBuffer>& indexBuffer) override;

		const std::vector<Ref<VertexBuffer>>& GetVertexBuffers() const override { return vertexBuffers; }
		const Ref<IndexBuffer>& GetIndexBuffer() const override { return indexBuffer; }

	private:
		uint32_t rendererID;

		std::vector<Ref<VertexBuffer>> vertexBuffers;
		Ref<IndexBuffer> indexBuffer;
	};
}
